<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>

    <style>
      .imgs {
        width: 300px;
        border: solid;
      }
      .imgs img {
        width: 100%;
      }
      .imgs .big {
      }
      .imgs .small {
        display: flex;
        justify-content: space-evenly;
      }
      .imgs .small div {
        width: 50px;
        border: solid 2px transparent;
      }

      .imgs .small div:hover {
        border-color: crimson;
        cursor: pointer;
      }

      .imgs .small .active {
        border-color: crimson;
      }
    </style>
  </head>
  <body>
    <div class="imgs" id="imgs">
      <div class="big">
        <img id="bigImg" src="./imgs/b1.jpg" alt="" />
      </div>
      <div class="small">
        <div class="active">
          <img data-thumb="./imgs/b1.jpg" src="./imgs/s1.jpg" alt="" />
        </div>
        <div>
          <img data-thumb="./imgs/b2.jpg" src="./imgs/s2.jpg" alt="" />
        </div>
        <div>
          <img data-thumb="./imgs/b3.jpg" src="./imgs/s3.jpg" alt="" />
        </div>
        <div>
          <img data-thumb="./imgs/b4.jpg" src="./imgs/s4.jpg" alt="" />
        </div>
        <div>
          <img data-thumb="./imgs/b5.jpg" src="./imgs/s5.jpg" alt="" />
        </div>
      </div>
    </div>
    <script>
      const bigImg = document.getElementById("bigImg");
      document.onclick = function (e) {
        const thumb = e.target.dataset.thumb;
        if (thumb === undefined) return;
        bigImg.src = thumb;
        // 清除active
        const old = document.querySelector("#imgs .active");
        old.classList.remove("active");
        // 添加active
        e.target.parentElement.classList.add("active");
      };
    </script>
  </body>
</html>
